package com.qf.dao;

import com.qf.entity.Developer;
import com.qf.entity.Project;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

/*
 * @ClassName projectDao
 * @Description TODO
 * @Author 86181
 * @Date 2022/8/25 19:31
 * @Version 1.0
 **/
public interface projectDao {
    //添加project
    @Insert(" <script>insert into project (\n" +
            "        <trim suffixOverrides=\",\">\n" +
            "       <if test=\"pname!=null and pname!=''\">\n" +
            "           pname,\n" +
            "       </if>\n" +
            "            <if test=\"starttime!=null\">\n" +
            "                starttime,\n" +
            "            </if>\n" +
            "            <if test=\"endtime!=null\">\n" +
            "                endtime,\n" +
            "            </if>\n" +
            "            <if test=\"did!=null and did!=''\">\n" +
            "                did,\n" +
            "            </if>\n" +
            "            <if test=\"cid!=null and cid!=''\">\n" +
            "                cid,\n" +
            "            </if>\n" +
            "\n" +
            "         </trim>\n" +
            "        )\n" +
            "        values (\n" +
            "                <trim suffixOverrides=\",\">\n" +
            "                    <if test=\"pname!=null and pname!=''\">\n" +
            "                        #{pname},\n" +
            "                    </if>\n" +
            "                    <if test=\"starttime!=null\">\n" +
            "                        #{starttime},\n" +
            "                    </if>\n" +
            "                    <if test=\"endtime!=null\">\n" +
            "                       #{endtime},\n" +
            "                    </if>\n" +
            "                    <if test=\"did!=null and did!=''\">\n" +
            "                        #{did},\n" +
            "                    </if>\n" +
            "                    <if test=\"cid!=null and cid!=''\">\n" +
            "                        #{cid},\n" +
            "                    </if>\n" +
            "                </trim>\n" +
            "        )</script>")
    void addProject(Project project);
    //结果集映射注解
    @Results(id="projectMap",value = {
            @Result(column = "pid",property = "pid"),
            @Result(column = "pname",property = "pname"),
            @Result(column = "starttime",property = "starttime"),
            @Result(column = "endtime",property = "endtime"),
            @Result(column = "did",property = "did"),
            @Result(column = "sid",property = "sid"),
            @Result(column = "cid",property = "cid"),
            @Result(column = "updatetime",property = "updatetime"),
            @Result(column = "did",property = "developer",javaType = Developer.class,
                    one = @One(select = "com.qf.dao.DeverloperDao.findDeveLopeByDid"
                            ,fetchType= FetchType.EAGER )
            ),
            @Result(column = "pid",property = "stages",
            many = @Many(select = "com.qf.dao.StageDao.findStagesByPid",fetchType = FetchType.EAGER)
            )
    })
        @Select("select* from project where status=1")
          List<Project> findproject();
    //根据工程id查询
    @ResultMap("projectMap")
    @Select("select*from project where pid=#{pid}")
    Project findProjectByPid(int pid);



}
